package com.lei.observer;

import java.util.ArrayList;
import java.util.List;

public abstract class Subject {
    private List<IObserver> list;
    public Subject(){
        list = new ArrayList<>();
    }
    public synchronized void addObserver(IObserver observer){
        list.add(observer);
    }
    public synchronized void delObserver(IObserver observer){
        list.remove(observer);
    }
    public synchronized void delObservers(IObserver observer){
        list.removeAll(list);
    }
    public synchronized void notifyObservers(Object o){
        for (IObserver observer : list) {
            observer.update(this,o);
        }
    }
}
